DEMO #1: Let's practice using the xy-coordinate plane by clicking on 4 locations.
Each location on the xy- coordinate plane can be described by two numbers written like this: (100, 50).
The first number is the x-coordinate which tells us how far to move right or left. (Right is +)
The second number is the y-coordinate which tells us how far to move up or down. (Up is +)
Click Run and follow the instructions on the stage and move the hedgehog around the field.
To navigate the page using the TAB key, first press ESC to exit the code editor.
color = "lightyellow"
stage.set_background("flowers")
stage.create_grid_overlay(50, color)
sprite = codesters.Sprite("hedgehog")
sprite.set_size(.5)
def main_event():
global rand_x
global rand_y
global guide
global asker
sprite.go_to(0,0)
guide = codesters.Text(" ", 0, 50, color)
rand_x = random.randrange(-200, 200, 50)
rand_y = random.randrange(-200, 200, 50)
point = (rand_x, rand_y)
asker = codesters.Text("Click on " + str(point), 0, 50, "black")
main_event()
score = 0
def pause():
stage.wait(.00001)
def click():
global score
asker.set_text(' ')
x = stage.click_x()
y = stage.click_y()
sprite.go_to(x, y)
stage.event_click(pause)
if (abs(x - rand_x) <=5 and abs(y - rand_y <= 5)):
choice = 1
elif (abs(y - rand_x) <=5 and abs(x - rand_y <= 5)):
choice = 2
else:
choice = False
stage.wait(1)
guide.go_to(rand_x, rand_y + 40)
if choice == 2:
guide.set_text("Oops! Looks like you mixed up x and y. Try again!")
guide.set_color("yellow")
elif choice == 1:
guide.set_text("Great job!")
guide.set_color("black")
score += 1
else:
guide.set_text("Here it is!")
sprite.go_to(rand_x, rand_y)
stage.wait(1)
guide.set_text("Try again!")
guide.set_color('red')
stage.wait(1)
guide.set_text(' ')
if score < 4:
main_event()
if score >= 4:
guide.go_to(0, 200)
guide.set_color("green")
guide.set_text("You've mastered the coordinate plane! Good work!")
tm = TestManager()
tm.display_success_message("Great job!")
stage.event_click(click)
stage.event_click(click)
tm = TestManager()
if score >= 4:
tm.display_success_message("Great job!")
Run Code
Activity Submitted!
Submit Work
Next Activity
Stop Running Code
Show Chart
Show Console
Reset Code Editor
Codesters How To (opens in a new tab)